home *** CD-ROM | disk | FTP | other *** search
- Path: wormer.fn.net!sysadmin@wormer.fn.net
- From: withheld@keepitpublic.com (Rusty Meathook)
- Newsgroups: comp.lang.c
- Subject: Re: QUEUE
- Date: Sun, 21 Apr 1996 22:02:15 GMT
- Organization: Feist Connections
- Message-ID: <4le47i$u0@wormer.fn.net>
- References: <4lcg0j$7if@itsop2.its.brooklyn.cuny.edu>
- NNTP-Posting-Host: mark411.fn.net
- X-Newsreader: Forte Agent .99b.112
-
- dzielins@its.brooklyn.cuny.edu (Daniel Zielinski) wrote:
-
- >Can anyone tell me what's wrong with my removeQueue function?
-
- >DataType
- >removeQueue(Queue *qp) {
- > Node *np;
- > DataType d;
- >
- > assert(!emptyQueue(*qp)); <------- THIS IS THE LINE
- > np=qp->front;
- > d=np->data;
- > qp->front=np->next;
- > if (qp->front==NULL)
- > qp->rear=NULL;
- > deleteNode(np);
- > return d;
- >}
-
- Why are you using assert() to test for that anyway? Why not:
-
- /* Untested code follows: */
- Queue *removeQueue(Queue *qp, DataType *d)
- {
- Node *np;
-
- if (emptyQueue(*qp))
- return (NULL);
-
- *d=qp->front->data;
-
- np=qp->front;
- qp->front=qp->front->next;
-
- if (qp->front==NULL)
- qp->rear=NULL;
-
- deleteNode(np);
-
- return (qp);
- }
-
- Regardless, your implimentation is a lot more complex and splintered
- than it needs to be. You might try implimenting your queue via a
- circular linked list so you don't have to fart around with the front
- and rear pointers....
-
-